/*
 * Copyright (C) 2010-2012 Susanta Tewari
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package coalescent.cef.pui;

import cef.event.Event;
import cef.pui.EventConstructionException;
import cef.pui.EventImpl;
import cef.pui.pob.Builder;
import cef.pui.pob.BuilderException;
import coalescent.cef.event.MLE_KC64ThetaEvent;
import coalescent.cef.pui.pob.Builders_Coa;
import coalescent.statistic.AC;

import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

/**
 * Implements {@code MLE_K69ThetaEvent} using the following properties.
 * <ul>
 *     <li>{@code coalescent.builder.AC.delegate = coalescent.cef.pui.pob.Builders_Coa$AC_KC64 | coalescent.cef.pui.pob.Builders_Coa$AC_K69_GT_File}</li>
 *     <li>{@code coalescent.builder.An.an = valid values are of the format f1^t1_f2^t2... where fi and ti are positive and represent the frequency domain, and the alleles on that frequency domain, respectively}</li>
 *     <li>{@code coalescent.builder.GeneTree.url = k69data:xml//URL }<a href="coalescent/cef/pui/pob/doc-files/k69data.xml.txt">file format</a>, must accompany the <a href="coalescent/cef/pui/pob/doc-files/k69data.xsd.txt">schema</a></li>
 *     <li>{@code coalescent.builder.theta.min = valid double string as specified in } {@link Double#parseDouble(java.lang.String)}</li>
 *     <li>{@code coalescent.builder.theta.max = valid double string as specified in } {@link Double#parseDouble(java.lang.String)}</li>
 *     <li>{@code coalescent.builder.theta.increment = valid double string as specified in } {@link Double#parseDouble(java.lang.String)}</li>
 * </ul>
 *
 * @since 1.4.0
 * @version version
 * @author Susanta Tewari
 * @history Created on Dec 19, 2012.
 */
public final class MLE_KC64ThetaEventImpl extends EventImpl implements MLE_KC64ThetaEvent {

    /**
     * statistic builder
     */
    private final Builder<AC<?, ?>> statisticBuilder;

    /** Field description */
    private final Builder<Double> theta_min_builder, theta_max_builder, theta_increment_builder;

    /**
     * Constructs ...
     *
     * @param props description
     *
     * @throws EventConstructionException description
     */
    public MLE_KC64ThetaEventImpl(final Properties props) throws EventConstructionException {

        super(props);

        super.processEventProperties(getImplementedEventInterfaces());

        statisticBuilder = Builders_Coa.of_AC(props, null);
        theta_min_builder = cef.pui.pob.Builders.of_Double(props, "min",
                "coalescent.builder.theta");
        theta_max_builder = cef.pui.pob.Builders.of_Double(props, "max",
                "coalescent.builder.theta");
        theta_increment_builder = cef.pui.pob.Builders.of_Double(props, "increment",
                "coalescent.builder.theta");
    }

    /**
     * Method description
     *
     * @return description
     */
    @Override
    protected List<Class<? extends Event>> getImplementedEventInterfaces() {

        final List<Class<? extends Event>> result = new ArrayList<>(2);

        result.add(MLE_KC64ThetaEvent.class);
        result.add(Event.class);

        return result;
    }

    /**
     * Method description
     *
     * @return
     * @throws BuilderException
     */
    @Override
    public AC<?, ?> getStatistic() throws BuilderException {
        return statisticBuilder.build();
    }

    /**
     * Method description
     *
     * @return description
     *
     * @throws BuilderException description
     */
    @Override
    public double getThetaMin() throws BuilderException {
        return theta_min_builder.build();
    }

    /**
     * Method description
     *
     * @return description
     */
    @Override
    public double getThetaMax() throws BuilderException {
        return theta_max_builder.build();
    }

    /**
     * Method description
     *
     * @return description
     */
    @Override
    public double getThetaIncrement() throws BuilderException {
        return theta_increment_builder.build();
    }
}
